<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Account extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		$user = $this->session->userdata('ych_user');
		if(!isset($user['user_id'])){
			$str = $_SERVER['REQUEST_URI'];
			header('Location: /mobile/login/index/index.html');
		}elseif((time() - $user['login_time']) > 3600*2){
			header('Location: /mobile/login/index/index.html');
		}
	}
	
	//交易记录
	function account_list($page = 0){
		$user = $this->session->userdata('ych_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		$this->load->model('Accountrecharge_model', 'recharge');
		$this->load->model('Payment_model', 'payment');
		//充值统计
		$resData = $this->recharge->get_accountrecharge_list($parms);
		$data['recharge_list'] = $resData['accountrecharge_list'];
		$recharge_status 		= $this->recharge->arrays("account_recharge_status");
		$payment_list 			= $this->payment->get_list();
		$recharge_list = array();
		foreach ($data['recharge_list'] as $recharge){
			$recharge['payment'] 		= isset($payment_list[$recharge['payment']]) ? $payment_list[$recharge['payment']]['name'] : '线下充值';
			$recharge['money'] 			= number_format($recharge['money'],2);
			$recharge['add_time'] 		= date('m-d H:i',$recharge['add_time']);
			$recharge['fstatus_text'] 	= $recharge_status[$recharge['fstatus']];
			$recharge_list[] = $recharge;
		}
		$data['recharge_list'] = $recharge_list;
		
		/////////////提现记录///////////////
		$this->load->model('Accountcash_model', 'cash');
		$resData = $this->cash->get_accountcash_list($parms);
		$cash_list = $resData['accountcash_list'];
		$cash_status 	= $this->cash->arrays("account_cash_status");
		$cash_lsit1 = array();
		foreach($cash_list as $cash){
			$cash['total'] 	= number_format($cash['total'],2);
			$cash['fee'] 	= number_format($cash['fee'],2);
			$cash['add_time'] = date('m-d H:i', $cash['add_time']);
			$cash['fstatus_text'] = $cash_status[$cash['fstatus']];
			$cash_lsit1[] = $cash;
		}
		$data['cash_list'] = $cash_lsit1;
		
		////////////////资金使用记录////////////////////////
		$this->load->model('Accountlog_model', 'accountlog');
		$resData = $this->accountlog->get_accountlog_list($parms);
		$account_log_list = $resData['accountlog_list'];
		$log_type 			= $this->accountlog->arrays("account_type");
		$account_log_list1 = array();
		foreach($account_log_list as $account_log){
			$account_log['ftype'] = $log_type[$account_log['ftype']];
			$account_log['add_time'] = date('m-d H:i', $account_log['add_time']);
			$account_log_list1[] = $account_log;
		}
		$data['account_log_list'] = $account_log_list1;
		$this->load->view('/mobile/account_list', $data);
	}
	
	/**
	 * 更多提现
	 * @param int $page
	 */
	function cashed_more($page = 0){
		$user = $this->session->userdata('ych_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		//充值统计
		$this->load->model('Accountcash_model', 'cash');
		$resData = $this->cash->get_accountcash_list($parms);
		$cash_list = $resData['accountcash_list'];
		$cash_status 	= $this->cash->arrays("account_cash_status");
		$cash_lsit1 = array();
		foreach($cash_list as $cash){
			$cash['total'] 	= number_format($cash['total'],2);
			$cash['fee'] 	= number_format($cash['fee'],2);
			$cash['add_time'] = date('m-d H:i', $cash['add_time']);
			$cash['fstatus_text'] = $cash_status[$cash['fstatus']];
			$cash_lsit1[] = $cash;
		}
		echo json_encode($cash_lsit1);
	}
	
	
	/**
	 * 更多充值
	 * @param int $page
	 */
	function recharge_log_more($page = 0){
		$user = $this->session->userdata('ych_user');
		$data = array();
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		$this->load->model('Accountrecharge_model', 'recharge');
		$this->load->model('Payment_model', 'payment');
		//充值统计
		$resData = $this->recharge->get_accountrecharge_list($parms);
		$data['recharge_list'] 	= $resData['accountrecharge_list'];
		$recharge_status 		= $this->recharge->arrays("account_recharge_status");
		$recharge_type 			= $this->recharge->arrays("account_recharge_type");
		$payment_list 			= $this->payment->get_list();
		$recharge_list = array();
		foreach ($data['recharge_list'] as $recharge){
			$recharge['payment'] 		= isset($payment_list[$recharge['payment']]) ? $payment_list[$recharge['payment']]['name'] : '线下充值';
			$recharge['money'] 			= number_format($recharge['money'],2);
			$recharge['fstatus_text'] 	= $recharge_status[$recharge['fstatus']];
			$recharge['add_time'] 		= date('m-d H:i', $recharge['add_time']);
			$recharge_list[] = $recharge;
		}
		echo json_encode($recharge_list);
	}
	
	/**
	 * 更多资金记录
	 * @param int $page
	 */
	function account_log_more($page = 0){
		$user = $this->session->userdata('ych_user');
		$parms['page_start'] = intval($page);
		$parms['page_size'] = 8;
		$parms['where']['user_id'] = $user['user_id'];
		$this->load->model('Accountlog_model', 'accountlog');
		$resData = $this->accountlog->get_accountlog_list($parms);
		$account_log_list = $resData['accountlog_list'];
		$log_type 			= $this->accountlog->arrays("account_type");
		$account_log_list1 = array();
		foreach($account_log_list as $account_log){
			$account_log['ftype'] 		= $log_type[$account_log['ftype']];
			$account_log['money'] 		= number_format($account_log['money'],2);
			$account_log['add_time'] 	= date('m-d H:i', $account_log['add_time']);
			$account_log_list1[] 		= $account_log;
		}
		echo json_encode($account_log_list1);
	}
	
}